public class ExerciseSheet {

    private static final short COLUMN_NUM = 5;

    /**
     * 格式化输出
     * @param ex：习题类对象
     * @param columns：每行算式的个数
     */
    public void formattedDisplay(Exercise ex, int columns) {
        int column  =1;
        int count = 1;
//        count代指序列
        while(ex.hasNext()) {
            if(column > columns) {
                System.out.println();
                column = 1;
            }
            System.out.printf("%3d.  ", count);
            System.out.print((ex.next()).fullString() + "\t");
            column++;
            count++;
        }
        System.out.println();
    }

    public void formattedDisplay(Exercise ex) {
        formattedDisplay(ex, COLUMN_NUM);
    }

    public static void main(String[] args) {
        ExerciseSheet sheet = new ExerciseSheet();
        Exercise exerciseAdd = new Exercise();
        Exercise exerciseSub = new Exercise();
        Exercise exerciseMix = new Exercise();

        /*产生加法算式习题*/
        System.out.println("---- 显示加法算式习题 ----");
        exerciseAdd.generateAdditionExercise(20);
        sheet.formattedDisplay(exerciseAdd, 4);

        /*产生减法算式习题*/
        System.out.println("---- 显示减法算式习题 ----");
        exerciseSub.generateSubstractExercise(20);
        sheet.formattedDisplay(exerciseSub, 5);

        /*产生加、减法混合算式习题*/
        System.out.println("---- 显示加减法混合算式习题 ----");
        exerciseMix.generateBinaryExercise(20);
        sheet.formattedDisplay(exerciseMix, 6);
    }
}



